/**
*@Author      :anlzou
*@Date        :22:18 2021/5/4
*@Github      :https://github.com/anlzou
*@Description :
*/
package com.anlzou.ways2read_input_from_console;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class W2RIFC {
    /**
     * 1.Using Buffered Reader Class
     * @throws IOException
     */
    public void fun1() throws IOException {
        // Enter data using BufferReader
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in));

        // Reading data using readLine
        String name = reader.readLine();

        // Printing the read line
        System.out.println(name);
    }

    /**
     * 2. Using Scanner Class
     */
    public void fun2(){
        // Using Scanner for Getting Input from User
        Scanner in = new Scanner(System.in);

        String s = in.nextLine();
        System.out.println("You entered string " + s);

//        int a = in.nextInt();
//        System.out.println("You entered integer " + a);
//
//        float b = in.nextFloat();
//        System.out.println("You entered float " + b);

        // closing scanner
        in.close();
    }

    /**
     * 3. Using Console Class
     */
    public void fun3(){
        // Using Console to input data from user
        String name = System.console().readLine();

        System.out.println("You entered string " + name);
    }

    /**
     * 4. Using Command line argument
     * @param args 命令行输入的参数
     */
    public void fun4(String[] args){
        // check if length of args array is
        // greater than 0
        if (args.length > 0) {
            System.out.println(
                    "The command line arguments are:");

            // iterating the args array and printing
            // the command line arguments
            for (String val : args)
                System.out.println(val);
        }
        else
            System.out.println("No command line "
                    + "arguments found.");
    }

/*--------------------------test--------------------------------*/
    public static void main(String[] args){
        W2RIFC w2rifc = new W2RIFC();
        //demo1
//        w2rifc.fun1();

        //demo2
//        w2rifc.fun2();

        /**
         * demo3
         * only on console, path this class local
         * run:
         *      java W2RIFC
         */
//        w2rifc.fun3();

        /**
         * demo4
         * only on console, path this class local
         * run:
         *      java  W2RIFC.java <argument>
         */
        w2rifc.fun4(args);
    }
}
